package com.itheima.edu.info.manger.service;

import com.itheima.edu.info.manger.dao.OotherStudentDao;
import com.itheima.edu.info.manger.dao.StudentDao;
import com.itheima.edu.info.manger.domain.Student;

public class StudentService {


    private OotherStudentDao studao=new OotherStudentDao();
    public boolean adddstudent(Student stu) {

     return studao.addtudent(stu);
    }
    public  boolean isExcies(String id) {

     Student[] stus=studao.findstudentid();
     boolean exists=false;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if(student !=null &&student.getId().equals(id)){
                exists=true;
                break;
            }
        }
        return exists;
    }

    public Student[] findstudent() {
    //调用dao层findstudent方法
     Student[] allstudent=studao.findstudentid();
    //判断是否有学生数据（有返回地址,没有为null
    boolean flog=false;
        for (int i = 0; i < allstudent.length; i++) {
           Student stus=allstudent[i];
           if(stus !=null){
         flog=true;
         break;
           }
        }
        if(flog){
            return allstudent;
        }else {
            return null;
        }
    }


    public void deleteid(String deid) {
     studao.deleteid(deid);
    }

    public void updatastudent(String upid, Student sutnew) {
        studao.updatastudent(upid,sutnew);
    }
}